// 创建属性管理：商品分类全局组局 相关的小仓库
import { defineStore } from "pinia";
// 引入接口
import { reqC1, reqC2, reqC3 } from "../../api/product/attr/index";
import type {CategoryResponseData,} from "../../api/product/attr/type";
import type { CategorStater } from "./type/type";


let useCategoryStore = defineStore("Category", {
  state: (): CategorStater => {
    return {
      c1Id: "",
      c2Id: "",
      c3Id: "",
      c1List: [],
      c2List: [],
      c3List: [],
    };
  },
  actions: {
    // 获取一级分类的方法
    async getCategory1() {
      let result: CategoryResponseData = await reqC1();
      if (result.code === 200) {
        this.c1List = result.data;
      }
    },
    // 获取一级分类的方法
    async getCategory2() {
      let result: CategoryResponseData = await reqC2(this.c1Id);
      if (result.code === 200) {
        this.c2List = result.data;
      }
    },
    // 获取一级分类的方法
    async getCategory3() {
      let result: CategoryResponseData = await reqC3(this.c2Id);
      if (result.code === 200) {
        this.c3List = result.data;
      }
    },
  },
});

export default useCategoryStore;
